<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Check extends CI_Controller {    
    function  __construct(){
        parent::__construct();
    }
    function index(){
        echo 'Làm gì thế?';
    }
    function checkip(){        
        $data->content=$this->load->view('check/ip',array(),true);
        $dt = $this->template->render($data);  
        $this->load->view('default/viewfull',$dt);
        ;
    }
    function checkpoint(){ 
        $user='';
        $mcre='';
        if(!empty($_POST)){            
            $this->session->set_userdata('iploc',$this->input->post('ip',true));
        }
        $iploc = $this->session->userdata('iploc'); 
        if($iploc){
            // $ip = explode('\n', $dulieu);
           $ip2 = explode("\n", str_replace("\r", "",$iploc ));           
           if(!empty($ip2)){
                $mm= array();
                $username=array_map('trim',$ip2);//mag username
              //  array_unique()
                $user = $this->db->where_in('username',$username)->get('users')->result();
                $iduser = '';
                foreach ($user as $user1){
                    $iduser[]= $user1->id;
                }
                //print_r($iduser);
                $credit =$this->db->where_in('iduser',$iduser)->get('credit')->result();
                if(!empty($credit)){
                    foreach ($credit as $credit1){
                        $mcre[$credit1->iduser][]=$credit1;
                    }
                }
                     
            }
        }
        $data->content =  $this->load->view('check/checkpoint', array('user'=>$user,'credit'=>$mcre),true);
        $dt = $this->template->render($data);  
        $this->load->view('default/viewfull',$dt);
    }
   
    function ajaxcheckip(){
        if(!empty($_POST)){
           // $ip = explode('\n', $dulieu);
           $ip2 = explode("\n", str_replace("\r", "", $this->input->post('ip',true)));           
           if(!empty($ip2)){
                $mm= array();
                $ip2=array_map('trim',$ip2);
                $this->db->select('ip');
                $this->db->where_in('ip',$ip2);                
                $mangip = $this->db->get('users')->result_array();   
                foreach ($mangip as $mangip){
                    $mm[]=trim($mangip['ip']);
                }                         
                $mm= array_unique ($mm);//loai bo phan tu trung nhau
                $cothesudung = array_diff ($ip2, $mm);//tra ve mang gom cac phan tu co trong $ip2 ma k co trong $mangip
                $khongthe=array_intersect ($ip2, $mm); //tra ve cac ip da ton tai  
                foreach ($cothesudung as $cothesudung){
                    echo $cothesudung.'<br>';
                }  
                foreach ($khongthe as $khongthe){
                    echo '<span>'.$khongthe.'</span><br>';
                }
                     
            }   
        }
    }
 
}